- name: Install packages
  package:
    name: ['os-autoinst-openvswitch', 'tunctl', 'network-scripts']
    state: latest
    enablerepo: "{{ openqa_repo }}"
  tags:
  - packages

- name: Enable ipv4_forward in sysctl
  sysctl: name=net.ipv4.ip_forward value=1 state=present sysctl_set=yes reload=yes

- name: Start openvswitch service
  service: name=openvswitch enabled=yes state=started
  with_sequence: "count={{ openqa_workers }}"

- name: Enable network service (needed for openvswitch devices)
  service: name=network enabled=yes state=started
  ignore_errors: yes

- name: openvswitch bridge device config
  copy: src=ifcfg-br0 dest=/etc/sysconfig/network-scripts/ifcfg-br0 owner=root group=root mode=0644
  notify:
  - restart network
  tags:
  - config

- name: Install ifup-pre-local script to create tap devices
  copy: src=ifup-pre-local dest=/sbin/ifup-pre-local owner=root group=root mode=0755

- name: openvswitch tap devices config
  template: src=ifcfg-tap.j2 dest=/etc/sysconfig/network-scripts/ifcfg-tap{{ item }} owner=root group=root mode=0644
  with_sequence: start=0 end={{ openqa_workers | int }}
  notify:
  - restart network
  tags:
  - config

- name: Install openvswitch sysconfig file
  copy: src=os-autoinst-openvswitch.sysconfig dest=/etc/sysconfig/os-autoinst-openvswitch owner=root group=root mode=0644

- name: Enable and start os-autoinst openvswitch service
  service: name=os-autoinst-openvswitch enabled=yes state=started
